package com.guigu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.ShopTypeInfo;
import com.guigu.service.ShopTypeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/shopType/")
public class ShopTypeInfoController {

    @Autowired
    ShopTypeInfoService shopTypeInfoService;

    //获取所有的分类
    @GetMapping("shopType.action")
    public List<ShopTypeInfo> queryAllShopType(){
        return  shopTypeInfoService.queryAllShopType();
    }

    //添加分类
    @PostMapping("shopType.action")
    public Map addShopType(@RequestBody ShopTypeInfo shopType){
        return  shopTypeInfoService.addShopType(shopType);
    }

    //分类分页
    @GetMapping("allShopType.action")
    public Page<ShopTypeInfo> selectAllShopType(ShopTypeInfo shopType,
                                                @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                                @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
      return    shopTypeInfoService.selectAllShopType(shopType,pageno,pagesize);
    }


    //根据id查询分类对象
    @GetMapping("shopType.action/{id}")
    public ShopTypeInfo queryTypeById(@PathVariable Integer id){
        return shopTypeInfoService.queryTypeById(id);
    }

    //编辑
    @PutMapping("shopType.action")
    public Map updateShopTypeById(@RequestBody ShopTypeInfo shopType){
        return shopTypeInfoService.updateShopTypeById(shopType);
    }

    //删除
    @DeleteMapping("delShopType.action/{id}")
    public Map deleteShopTypeById(@PathVariable Integer id){
        return  shopTypeInfoService.deleteShopTypeById(id);
    }

    //验证分类名称是否重复
    @GetMapping("ckShopType.action/{name}")
    public Map ckShopTypeByName(@PathVariable String name){
        return shopTypeInfoService.ckShopTypeByName(name);
    }
}
